package com.ruoyi.system.controller;

import com.google.protobuf.ByteString;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.system.netty.NettyClientHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import proto.client.ProtoCmd;

import java.util.Map;

/**
 * netty测试通道
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/netty")
public class NettyController extends BaseController
{
    @Autowired
    private NettyClientHandler nettyClientHandler;

    /**
     * 获取参数配置列表
     */
    @GetMapping("/request")
    public String request(Map<String,Object> config)
    {
        try {
            ProtoCmd.RequestCmd.Builder cmd=ProtoCmd.RequestCmd.newBuilder();
            cmd.setPact(Integer.parseInt(config.get("pact").toString()));
            cmd.setCode(Integer.parseInt(config.get("code").toString()));
            cmd.setData((ByteString) config.get("data"));
            nettyClientHandler.sendMsg(cmd.build());
        }catch (Exception e){
            return e.getMessage();
        }
        return "请求成功";
    }

}
